package com.summer.JavaUsefulClass;

import org.junit.Test;

import java.util.Arrays;

public class StringTest {

    //1. String 声明为final ,不可被继承
    //2. String 实现了Serializable接口，表示字符串是支持序列化的
    //实现了Comparable接口，表示String可以比较大小
    //3.String内部定义了final char[] value 用于存储字符串数据
    //4.String:代表不可变的字符序列
    @Test
    public void test01(){
        String s1 = "abc";//字面量的定义方式 字符串值声明在字符串常量池中
        String s2 = "abc";
        String s3 = new String("abc");
        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
        String s4 = "abc";
        String s5 = s4.replace('a','b');
        System.out.println(s4);
        System.out.println(s5);
       // String s6 = new String(char[] a);
        //String s7 = new String(char[] a,int startIndex,int count);
    }
    @Test
    public void test02(){
        String s1 = "javaee";
        String s2 = "javaee";
        String s3 = new String("javaee");
        String s4 = new String("javaee");
        System.out.println(s1==s2);
        System.out.println(s3==s4);
        String s6 = s3.intern();
        System.out.println(s6 == s2);
    }
    @Test
    public void test03(){
        String s1 = "javaee";
        String s3 = "JAVAEE";
        String s2 = " kkk  ";
        System.out.println(s1.length());
        System.out.println(s1.charAt(0));
        System.out.println(s1.isEmpty());
        System.out.println(s1.toLowerCase());
        System.out.println(s1.toUpperCase());
        System.out.println("-----"+s2+"------"+"------"+s2.trim()+"--------");
        System.out.println(s2.equalsIgnoreCase(s2));
        System.out.println(s1.concat(s2));
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.substring(1, 2));//左闭右开
        System.out.println(s1.endsWith("ee"));
        System.out.println(s1.startsWith("ja"));
        System.out.println(s1.startsWith("ja",2));//从第几个下标开始
        System.out.println(s1.contains("java"));
        System.out.println(s1.indexOf("ja"));
        System.out.println(s1.indexOf("ee", 3));
        System.out.println(s1.lastIndexOf("ee"));
        System.out.println(s1.lastIndexOf("ee", 4));
    }
    @Test
    public void test04(){
        String s1 = "summer is handsome boy";
        String s2 = s1.replace("is ","is a ");
        System.out.println(s1+"----"+s2);

    }

    @Test
    public void test05(){
        //String 与基本数据类型、包装类之间的转换。
        String str1 = "123";
        int num = Integer.parseInt(str1);
        String str2 = String.valueOf(num);
        String str3 = num + "";
        System.out.println(str1 == str3);

        //string 与char[] 之间转换
        String str4 = "abc123";
        char[] chars = str4.toCharArray();
        System.out.println(Arrays.toString(chars));
        //char[] 转化 Srting
        String srt5 = new String(chars);
        System.out.println(srt5);
        //string 与byte[] 之间转换
        byte[] bytes = srt5.getBytes();
        System.out.println(Arrays.toString(bytes));
    }
}
